<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
<title>Insert title here</title>

<style type="text/css"> 
.tip { 
	width:200px; 
	border:2px solid #ddd; 
	padding:8px; 
	background:#f1f1f1; 
	color:#666; 
} 
</style> 
<script type="text/javascript"> 
  
//方法1 
function mousePos(e){ 
  var x,y; 
  var e = e||window.event; 
  return { 
    x:e.clientX+document.body.scrollLeft + document.documentElement.scrollLeft, 
    y:e.clientY+document.body.scrollTop + document.documentElement.scrollTop 
  }; 
}; 
  
//方法2 
//Firefox支持属性pageX,与pageY属性，这两个属性已经把页面滚动计算在内了, 
//在Chrome可以通过document.body.scrollLeft，document.body.scrollTop计算出页面滚动位移， 
//而在IE下可以通过document.documentElement.scrollLeft ，document.documentElement.scrollTop 
function getMousePos(event) { 
      var e = event || window.event; 
      var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; 
      var scrollY = document.documentElement.scrollTop || document.body.scrollTop; 
      var x = e.pageX || e.clientX + scrollX; 
      var y = e.pageY || e.clientY + scrollY; 
      //alert('x: ' + x + '\ny: ' + y); 
      return { 'x': x, 'y': y }; 
    } 
  
function test(e){ 
document.getElementById("mjs").innerHTML = getMousePos(e).x+','+getMousePos(e).y;
};
</script> 

</head>
<body>
<h1>HOME</h1>
<div id="mjs" class="tip">获取鼠标点击位置坐标</div> 
<div id="test" style="width:350px;height:330px;background:#ccc;"></div> 
<!-- <div id="test" style="width:300px;height:300px;background:#ccc;" onmousemove="test(event)"></div>  -->

<script>
	var startX = 0;
	var startY = 0;
	
	var endX = 0;
    var endY = 0;
	
	var obj = document.getElementById("test");
	obj.addEventListener('touchmove', function(event) {
		// 如果这个元素的位置内只有一个手指的话
        if (event.targetTouches.length == 1) {
        	
        	var touch = event.targetTouches[0];
        	document.getElementById("mjs").innerHTML = touch.pageX;
        	/* 
        	var endX = touch.pageX;
            var endY = touch.pageY;
            
            var dtX = endX - startX;
            var dtY = endY - startY;
            document.getElementById("mjs").innerHTML = "("+dtX+","+dtY+")";
             */
		}
	});
	
	
	obj.addEventListener('touchstart', function(event) {
        // 如果这个元素的位置内只有一个手指的话
        if (event.targetTouches.length == 1) {
            var touch = event.targetTouches[0];
            // 把元素放在手指所在的位置
            startX = touch.pageX;
            startY = touch.pageY;
			
            // touchStart.value = pressX + ';' + pressY;
        }
    }, false);
/* 	
	obj.addEventListener('touchend', function(event) {
        // 如果这个元素的位置内只有一个手指的话
        if (event.targetTouches.length == 1) {
            
            // var touch = event.targetTouches[0];
            var dtX = endX - startX;
            var dtY = endY - startY;
            // 把元素放在手指所在的位置
            // touchEnd.value=touch.pageX + ';' + touch.pageY;
            document.getElementById("mjs").innerHTML = "("+dtX+","+dtY+")";
        }
    }, false);
 */	
</script>

</body>
</html>